<template>
    <div class="example-container">
        <div class="card">
            <div class="title">发送短信接口: /api/app/basic-demo-12jasx/demo/sendSms</div>
            <div><span>输入签名：</span><input type="search" placeholder="请输入签名" v-model="sms.signname"></div>
            <div><span>输入模板代码：</span><input type="search" placeholder="请输入模板代码" v-model="sms.templatecode"></div>
            <div><span>输入请求id：</span><input type="search" placeholder="请输入请求id" v-model="sms.requestid"></div>
            <div><span>输入电话号码：</span><input type="search" placeholder="请输入电话号码" v-model="sms.phonenumber"></div>
            <div><span>输入模板代码的参数：</span><input type="search" placeholder="请输入模板代码的参数" v-model="sms.templateparams">
            </div>
            <div><span>输入短信调用方识别码：</span><input type="search" placeholder="请输入短信调用方识别码" v-model="sms.accessKeyId"></div>
            <div><span>输入短信渠道：</span><input type="search" placeholder="请输入短信渠道" v-model="sms.channel"></div>
            <div><span>输入时间戳：</span><input type="search" placeholder="请输入时间戳" v-model="sms.timestamp"></div>
            <div>
                <button @click="sendSms_(sms)">测试</button>
            </div>
            <span>返回数据:</span>
            <textarea v-model="returndata.sms" readonly></textarea>
        </div>
        <div class="card">
            <div class="title">发送邮件接口：/api/app/basic-demo-12jasx/demo/sendMail</div>
            <div><span>输入收件人邮箱：</span><input type="search" placeholder="请输入收件人邮箱" v-model="mail.to"></div>
            <div><span>输入收件人姓名：</span><input type="search" placeholder="请输入收件人姓名" v-model="mail.toName"></div>
            <div><span>输入主题：</span><input type="search" placeholder="请输入主题" v-model="mail.subject"></div>
            <div><span>输入内容：</span><input type="search" placeholder="请输入内容" v-model="mail.inner"></div>
            <div>
                <button @click="sendMail_(mail)">测试</button>
            </div>
            <span>返回数据:</span>
            <textarea v-model="returndata.mail" readonly></textarea>
        </div>
        <div class="card">
            <div class="title">请求所有省份接口： /api/app/basic-demo-12jasx/demo/getAllProvince</div>
            <div>
                <button @click="getAllProvince_">测试</button>
            </div>
            <span>返回数据:</span>
            <textarea v-model="returndata.province" readonly></textarea>
        </div>
        <div class="card">
            <div class="title">获取城市天气接口： /api/app/basic-demo-12jasx/demo/getSimpleWeatherByCityName</div>
            <div><span>输入城市名字：</span><input type="search" placeholder="请输入城市名字" v-model="city"></div>
            <div>
                <button @click="getSimpleWeatherByCityName_(city)">测试</button>
            </div>
            <span>返回数据:</span>
            <textarea v-model="returndata.weather" readonly></textarea>
        </div>
    </div>
</template>

<script>
    import {sendMail, sendSms, getAllProvince, getSimpleWeatherByCityName} from "../../service/basis";

    export default {
        name: "index",
        data() {
            return {
                mail: {
                    to: '',
                    toName: '',
                    subject: '',
                    inner: '',
                    annexfile: ''
                },
                sms: {
                    signname: '',
                    templatecode: '',
                    requestid: '',
                    phonenumber: '',
                    templateparams: ''
                },
                city: '',
                returndata: {
                    sms: '',
                    mail: '',
                    province: '',
                    weather: ''
                }

            }
        },
        methods: {
            async sendSms_(data) {
                try {
                    this.returndata.sms = JSON.stringify(await sendSms(data), null, 4)
                } catch (e) {
                    this.returndata.sms = e
                }
            },
            async sendMail_(data) {
                try {
                    this.returndata.mail = JSON.stringify(await sendMail(data), null, 4)
                } catch (e) {
                    this.returndata.mail = e
                }
            },
            async getSimpleWeatherByCityName_(data) {
                try {
                    this.returndata.weather = JSON.stringify(await getSimpleWeatherByCityName(data), null, 4)
                } catch (e) {
                    this.returndata.weather = e
                }
            },
            async getAllProvince_() {
                try {
                    this.returndata.province = JSON.stringify(await getAllProvince(), null, 4)
                } catch (e) {
                    this.returndata.province = e
                }
            }
        }
    }
</script>
